import { randomTxt, randomTxtLibrary } from '../../utils/data';
import { host } from '../global.config';
import { TestConfigEntity } from '../test.entity';
const projectName = `自动化测试项目${randomTxtLibrary('number', 1)}`;
const projectType = randomTxt(['Kanban', 'Scrum'], 1);
const placeholder = randomTxtLibrary('uppercase', 4);
const members = ['aa_a1'];
const resultTypeIcon = {
  Scrum: 'thy-icon-scrum-fill',
  Kanban: 'thy-icon-kanban-square-fill',
};
export const AgileProjectConfig: TestConfigEntity = {
  title: 'Agile模块添加项目测试',
  pageUrl: `${host.url}/agile/projects`, // 访问Agile
  screenshotName:'agile_add_project_tests',
  operation: {
    type: 'click',
    name: 'addProjectBut',
    selector: 'a:has-text("新建项目")',
  },
  from: [
    {
      type: 'fill',
      name: 'projectName',
      selector: 'input[placeholder="输入项目名称（不超过32字符）"]',
      label: '项目名称',
      value: projectName,
      err_msg: ['项目名称不能为空', '该选项输入值长度不能大于32'],
    },
    {
      type: 'click',
      name: 'projectType',
      label: '项目类型',
      selector: `.form-check-label:has-text("${projectType}")`,
      value: projectType,
    },
    {
      type: 'fill',
      name: 'placeholder',
      selector: 'thy-input[name="styx-input-identifier"] input',
      label: '项目标识',
      value: placeholder,
      err_msg: [
        '项目标识不能为空',
        '英文字母/数字/下划线/连接线,最后一位不能为数字（不超过10字符）',
        '该项目标识已被使用，请改用其他项目标识。',
      ],
    },
    {
      type: 'fill',
      name: 'description',
      label: '描述',
      selector: 'textarea[name="description"]',
      value: '项目描述',
    },
    {
      type: 'members',
      name: 'members',
      selector: '.thy-icon-user-add',
      label: '成员',
      value: members,
      list_selector: '.avatar-name',
      okBtn: 'button:has-text("确认")',
    },
    {
      type: 'click',
      name: 'okBtn',
      selector: 'button:has-text("确定")',
    },
  ],
  testPage: {
    pageUrl: `${host.url}/agile/projects`, // 访问项目首页看列表中是否存在创建的项目
    btnGroup: [
      {
        type: 'click',
        name: 'sortBtn',
        selector: 'a[thytooltip="排序"]',
      },
      {
        type: 'click',
        name: 'create_at',
        selector: '.action-menu-item .name:has-text("创建时间")',
      },
    ],
    result: [
      {
        id: '101',
        type: 'class',
        selector: `tbody > tr:nth-child(1) > td:nth-child(1) .icon-text`,
        des: '测试新加项目类型',
        value: resultTypeIcon[projectType],
      },
      {
        id: '102',
        type: 'text',
        selector: 'tbody > tr:nth-child(1) > td:nth-child(1)',
        des: '测试新加项目名称',
        value: projectName,
      },
      {
        id: '103',
        type: 'text',
        selector: 'tbody > tr:nth-child(1) > td:nth-child(3)',
        des: '测试新加项目标识',
        value: placeholder,
      },
      {
        id: '104',
        type: 'text',
        selector: 'tbody > tr:nth-child(1) > td:nth-child(4)',
        des: '测试新加项目人数',
        value: String(members.length + 1),
      },
    ],
  },
};
